package org.xteam.box2text.old;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.xteam.box2text.Frame;
import org.xteam.box2text.Point;
import org.xteam.box2text.TextStruct;

public class IOperator extends Operator implements IPlaceableBox {
	
	public IOperator(Box...boxes) {
		super(boxes);
	}
	
	public IOperator(int hs, int is, Box...boxes) {
		super(boxes);
		options.put("hs", hs);
		options.put("is", is);
	}
	
	public IOperator(int hs, int is, List<Box> arguments) {
		super(arguments);
		options.put("hs", hs);
		options.put("is", is);
	}

	public IOperator(List<Box> boxes) {
		super(boxes);
	}
	
	public IOperator(Map<String, Integer> options, List<Box> arguments) {
		super(options, arguments);
	}

	public Box removeVertical(boolean removeRow) {
		return new IOperator(options, removeVertical(arguments, removeRow));
	}

	public int width(Frame frame) {
		return width(arguments, frame);
	}

	public TextStruct place(Frame frame, TextStruct textStruct, int context) {
		if (context == OperatorKinds.V) {
			int Is = frame.getIs(options());
			return new HOperator(options(), arguments).place(frame.setPoint(frame.x()+Is,frame.y()), textStruct, OperatorKinds.V);
		}
		return new HOperator(options(), arguments).place(frame, textStruct, context);
	}

	public Point length(Frame frame, int context) {
		if (context == OperatorKinds.V) {
			int is = frame.getIs(options);
			Point bp = new HOperator(options, arguments).length(frame, OperatorKinds.V);
			return new Point(bp.width() + is, bp.height());
		}
		return new HOperator(options, arguments).length(frame, OperatorKinds.H);
	}
	
	@Override
	public List<Box> normalizeGroups(boolean splice) {
		return Arrays.asList(new Box[] { new IOperator(options, normalizeChildren(true)) });
	}

}
